package com.gitee.hljdrl.lite.app;

import android.app.Application;

import com.gitee.hljdrl.lite.Lite;
import com.gitee.hljdrl.lite.config.AppConf;
import com.ffsky.logger.L;
import com.gitee.hljdrl.utils.os.AndroidUtil;

public abstract class LiteApplication extends Application {


    @Override
    public void onCreate() {
        super.onCreate();
        onCreateStart();
        if (AndroidUtil.inMainProcess(this)) {
            onLogger();
            onLitePack();
            onAppEnv();
            onAppCreate();
        } else {
            onCreateChannel();
        }
    }

    public void onCreateStart() {

    }

    public abstract void onAppCreate();

    public abstract void onCreateChannel();

    protected void onLitePack() {
        L.i("LiteApplication", "onLitePack");
        AppInterface appInterface = buildAppInterface();
        new Lite.Builder()
                .setAppConf(buildAppConf())
                .setApplication(this)
                .setAppInterface(appInterface)
                .apply();

        registerActivityLifecycleCallbacks(appInterface);
    }

    protected abstract void onAppEnv();

    protected void onLogger() {
        L.i("LiteApplication", "onCreate");
    }

    protected abstract AppConf buildAppConf();

    protected abstract AppInterface buildAppInterface();
}
